<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>添加商品</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <link rel="stylesheet" href="css/iconfont.css" />
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/companydata.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	</head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader()
		    </script>
	    </section>
	    
	    <!-- 页面  -->
	    <section class="AllContent">
	    	<form>
	    		<div class="FormStyle">
	    			<ul>
	    				<li>网点名称：</li>
        				<li><input type="text" id="name" name="name" value="" placeholder="网点名称" /></li>
        				<li>用户账号：</li>
        				<li><input type="text" id="adminUser" name="adminUser" value="" placeholder="管理员用户名" /></li>
        				<li>用户密码：</li>
        				<li><input type="password" id="password" name="password" value="" placeholder="管理员用户密码" /></li>
        				<li>联系人：</li>
        				<li><input type="text" id="link_man" name="link_man" value="" placeholder="联系人" /></li>
        				<li>联系电话：</li>
        				<li><input type="text" id="phone" name="phone" value="" placeholder="联系电话" /></li>
        				<li>省：</li>
        				<li>
							<select  type="text"  id="province" name="province"></select>
        				</li>
        				<li>市：</li>
        				<li>
							<select type="text" id="city" name="city" ></select>
        				</li>
        				<li>区：</li>
        				<li>
							<select type="text" id="area" name="area" ></select>
        				</li>
        				<li>街道地址：</li>
        				<li><input type="text" id="address" name="address" value="" placeholder="街道地址"/></li>
        				<li>邮箱：</li>
        				<li><input type="text" id="email" name="email" value="" placeholder="邮箱" /></li>
        				
        				<li>状态：</li>
        				<li>
        					<select name="status" id="status">
                                <option value="正常">正常</option>
                                <option value="关闭">关闭</option>
                            </select>
        				</li>
	    			</ul>
	    			<div class="FormPhoto">
	    				<img id="branch_pic" name="branch_pic" src="images/Photo2.png">
	    				<!--<input type="file" id="file_upload"/>-->
	    				<div class="ImageHosting">空间图片</div>
	    			</div>
	    			<p style="margin:0px 4.5%;font-size:0.83em;color:#999;margin-top:10px;font-family: arial;line-height:23px;">上传图片大小不能超过2M，最佳尺寸为200x200px</p>
	    			
	    			<button class="NextButton" type="button" onclick="addbranch();">保存</button>
	    		</div>
	    	</form>
	    	
	    	<div class="SlidingLayer">
	    		<div style="overflow: hidden;background-color:#fff;">
	    			<span class="ImageHostingTitle">空间图片</span>
	    			<img class="CloseImg" style="width:30px;" src="images/remover.png">
	    		</div>
	    		<ul id="piclist">
	    			
	    		</ul>
	    	</div>
	    </section>
	    
	    <section>
	    	<div class="MaskLayer">
		    	<div class="MaskContent">
		    		<p><img src="images/loading5.gif"></p>
		    		<p>正在添加...</p>
		    	</div>
	    	</div>
	    </section>
		
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript" src="js/jsAddress.js" ></script>
	<script type="text/javascript">
		$('.AllHeader li:eq(1)').text('添加网点')
	    
	    $(function () {
	        document.addEventListener('deviceready', onDeviceReady, true);
	        addressInit('province', 'city', 'area');
	        $("#file_upload").change(function() {
				var $file = $(this);
				var fileObj = $file[0];
				var windowURL = window.URL || window.webkitURL;
				var dataURL;
				var $img = $("#branch_pic");
				 
				if(fileObj && fileObj.files && fileObj.files[0]){
				dataURL = windowURL.createObjectURL(fileObj.files[0]);
				$img.attr('src',dataURL);
				}else{
				dataURL = $file.val();
				var imgObj = document.getElementById("branch_pic");
				imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
				imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
				 
				}
			});
	        getpic('全部',1);
	    });
	    var branchlist = false;
	    function onDeviceReady() {
	        document.addEventListener("backbutton", onBackKeyDown, false);
	    }
	    function onBackKeyDown() {
	        openUrl("index.html");
	    }
	    function addbranch() {
	        var name = $("#name").val();
	        var adminUser = $("#adminUser").val();
	        var password = $("#password").val();
	        var link_man = $("#link_man").val();
	        var phone = $("#phone").val();
	        var province = $("#province").val();
	        var city = $("#city").val();
	        var area = $("#area").val();
	        var address = $("#address").val();
	        var email = $("#email").val();
	        var status = $("#status").val();
	        var baiduxy = $("#baiduxy").val();
	        var googlexy = $("#googlexy").val();
	        var branch_pic = $("#branch_pic").attr('src');
	
	        if (empty(name)) {
	            alertMessage("网点名称不能为空！");
	            return;
	        }
	        if (empty(adminUser)) {
	            alertMessage("网点管理员名不能为空！");
	            return;
	        }
	        var datas = {access_token:getToken(),name:name,adminUser:adminUser,password:password,link_man:link_man,phone:phone
	        ,province:province,city:city,area:area,address:address,email:email,status:status,baiduxy:baiduxy,googlexy:googlexy,branch_pic:branch_pic};
	        $.ajax({
	            type: "post",
	            url: getServerUrl() + "/Open/Company/addbranch",
	            dataType: 'json',
	            data: datas,
	            success: function (json) {
	                if (json.result == "1") {
	                    mui.openWindow({
							 url: 'ScreentoneList.html', 
						    id:'ScreentoneList.html'
						});
	                } else {
	                    alertMessage("添加网点错误:[" + json.error_description + "]");
	                }
	            }
	        });
	    }
	</script>
</html>
